<template>
  <div class="articles02">
    <lw-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="getList"
    >
      <template #default>
        <van-cell
          v-for="(item, i) in list"
          :key="i"
          :to="'/article/' + item.id"
        >
          <div class="cell-header">
            <van-image
              width="30"
              height="30"
              :src="
                item.original_status.user.photo_domain +
                item.original_status.user.profile_image_url.split(',')[0]
              "
            />
            <div class="right-header">
              <div class="author">
                {{ item.original_status.user.screen_name }}
              </div>
              <div class="pubtime">{{ item.original_status.timeBefore }}</div>
            </div>
          </div>
          <p v-html="item.original_status.description"></p>
          <div class="cell-footer">
            <div class="item">
              <van-icon name="share-o" />
              <div class="num">{{ item.original_status.retweet_count }}</div>
            </div>
            <div class="item">
              <van-icon name="chat-o" />
              <div class="num">{{ item.original_status.reply_count }}</div>
            </div>
            <div class="item">
              <van-icon name="good-job-o" />
              <div class="num">{{ item.original_status.like_count }}</div>
            </div>
          </div>
        </van-cell>
      </template>
    </lw-list>
  </div>
</template>

<script>
import { Cell, Image as VanImage, Icon } from "vant";
import LwList from "@/components/defineComponents/Lw-list";
import { getArticles } from "@/api/index.js";

export default {
  name: "Articles02",
  data() {
    return {
      page: 1,
      list: [],
      finished: false,
      loading: false,
    };
  },
  methods: {
    async getList() {
      if (this.finished === true) {
        return;
      }

      this.loading = true;
      let result = await getArticles({ page: this.page });
      this.loading = false;
      if (result.result && result.result.indexOf("已加载") !== -1) {
        this.finished = true;
      } else {
        this.list = this.list.concat(result.items);
        this.page++;
      }
    },
  },
  components: {
    "van-cell": Cell,
    "van-image": VanImage,
    "van-icon": Icon,
    LwList,
  },
};
</script>

<style lang="less" scoped>
.cell-header {
  display: flex;
  height: 1rem;
  .right-header {
    font-size: 0.3rem;
    line-height: 0.4rem;
    padding-left: 0.2rem;
    .pubtime {
      color: #999;
    }
  }
}

.cell-footer {
  display: flex;
  height: 0.5rem;
  align-items: center;
  .item {
    display: flex;
    font-size: 0.3rem;
    width: 1.5rem;
    height: 0.5rem;
    align-items: center;
    .num {
      padding: 0 0.1rem;
    }
  }
}
</style>
